'use strict';

angular.module('app')
  .controller('registerCtrl', [
    '$scope',
    '$http',
    '$interval',
    '$state',
    function($scope, $http, $interval, $state) {
      /*注册*/
      $scope.submit = function() {
        // console.log($scope.user);
        $http.post('data/regist.json', $scope.user)
          .then(function(success) {
              console.log(success);
              $state.go('login');
            },
            function(error) {
              console.log(error);
            });
      };
      /*发送短信*/
      var count = 60;
      $scope.send = function() {
        count = 60;
        $http.get('/data/code.json')
          .then(function(success) {
            if (success.data.state === 1) {
              $scope.time = '60s';
              console.log($scope.time);
              var interval = $interval(function() {
                if (count <= 0) {
                  $interval.cancel(interval);
                  $scope.time = '';
                  return;
                }
                count--;
                $scope.time = count + 's';
              }, 1000);
            }
          }, function(error) {
            console.log(error);
          })
      }
    }
  ])
